#ifndef __MOD_ETHER__
#define __MOD_ETHER__

#include "decoder.hpp"
#include <pcre.h>



//==========================================================

class EtherDecoder : public Decoder
{
private:

public:
  Record rec;
  Table<Node> * node;

  EtherDecoder () 
  {
    this->node = new Hash<Node> (12347);
  };
  ~EtherDecoder () 
  {
    delete this->node;
  };
  
  Record * decode (Packet & pkt, Record & prev);
  NDecFilter * makeFilter (string &name);  
};



//==========================================================

class EtherFilter : public NDecFilter 
{
  friend class EtherDecoder;

private:
  static const int ADDR_LEN = 6;

  // argument activation
  bool active; 
  // compared data
  u_int8_t macAddr [ADDR_LEN];
  
  enum FilterType
    {
      FT_SRC_ADDR,
      FT_DST_ADDR,
    } type;

  static pcre * re ;

public:
  EtherFilter (FilterType t) : active (false), type (t)
  {
    if (this->type == FT_SRC_ADDR || this->type == FT_DST_ADDR)
      {
	this->setResultType (RT_RAW);
      }

//    if (re == NULL)
//      {
//	char * emsg;
//	int eoff;
//	assert (re != NULL);
//	re = pcre_compile ("^([0-9A-Fa-f]{2})[:\\-]{0,1}"
//			   "([0-9A-Fa-f]{2})[:\\-]{0,1}"
//			   "([0-9A-Fa-f]{2})[:\\-]{0,1}"
//			   "([0-9A-Fa-f]{2})[:\\-]{0,1}"
//			   "([0-9A-Fa-f]{2})[:\\-]{0,1}"
//			   "([0-9A-Fa-f]{2})$", 0, &emsg, &eoff, NULL);
//      }
  }
  ~EtherFilter () {}

  bool setup (string &arg);
  void check (NDecResult &res);
};


#endif /* __MOD_ETHER__ */
